function [ w ] = similarity( num_digits )
    [zero one two three four five six seven eight nine ...
    zero_t one_t two_t three_t four_t five_t six_t seven_t eight_t nine_t test training] = parsedata();
 
    % TODO: 
    % -think about increasing m (compare a pixel to a window of pixels?)
    % -figure out how to exhaustively check every single combination of the
    % two training sets without double counting

    % N = number of training examples
    % m = number of variables in the example (in this case 16x16 pixels)

    N = (num_digits*10)^2; %size(training,1)^2;
    m = 256;
    T = zeros(N,m);
    t_count = 1;
    labels = zeros(N,1);
    trainingx = zeros(10*num_digits,257);
    trainingy = zeros(10*num_digits,257);

    % this super nasty code makes 2 matrices of training data arranged in
    % this format:
    % num_digits entries of 0, num_digits entries of 1, ...
    % trainingx is the first num_digits from the top, trainingy is the last
    % num_digits from the bottom
    trainingx(:,1) = [zeros(num_digits,1);ones(num_digits,1);2*ones(num_digits,1); ...
        3*ones(num_digits,1);4*ones(num_digits,1);5*ones(num_digits,1); ...
        6*ones(num_digits,1);7*ones(num_digits,1);8*ones(num_digits,1); ...
        9*ones(num_digits,1)];
    trainingx(1:num_digits,2:end) = zero(1:num_digits,:);
    trainingx(1+num_digits:2*num_digits,2:end) = one(1:num_digits,:);
    trainingx(1+2*num_digits:3*num_digits,2:end) = two(1:num_digits,:);
    trainingx(1+3*num_digits:4*num_digits,2:end) = three(1:num_digits,:);
    trainingx(1+4*num_digits:5*num_digits,2:end) = four(1:num_digits,:);
    trainingx(1+5*num_digits:6*num_digits,2:end) = five(1:num_digits,:);
    trainingx(1+6*num_digits:7*num_digits,2:end) = six(1:num_digits,:);
    trainingx(1+7*num_digits:8*num_digits,2:end) = seven(1:num_digits,:);
    trainingx(1+8*num_digits:9*num_digits,2:end) = eight(1:num_digits,:);
    trainingx(1+9*num_digits:end,2:end) = nine(1:num_digits,:);

    trainingy(:,1) = [zeros(num_digits,1);ones(num_digits,1);2*ones(num_digits,1); ...
        3*ones(num_digits,1);4*ones(num_digits,1);5*ones(num_digits,1); ...
        6*ones(num_digits,1);7*ones(num_digits,1);8*ones(num_digits,1); ...
        9*ones(num_digits,1)];
    trainingy(1:num_digits,2:end) = zero(end:-1:end-num_digits+1,:);
    trainingy(1+num_digits:2*num_digits,2:end) = one(end:-1:end-num_digits+1,:);
    trainingy(1+2*num_digits:3*num_digits,2:end) = two(end:-1:end-num_digits+1,:);
    trainingy(1+3*num_digits:4*num_digits,2:end) = three(end:-1:end-num_digits+1,:);
    trainingy(1+4*num_digits:5*num_digits,2:end) = four(end:-1:end-num_digits+1,:);
    trainingy(1+5*num_digits:6*num_digits,2:end) = five(end:-1:end-num_digits+1,:);
    trainingy(1+6*num_digits:7*num_digits,2:end) = six(end:-1:end-num_digits+1,:);
    trainingy(1+7*num_digits:8*num_digits,2:end) = seven(end:-1:end-num_digits+1,:);
    trainingy(1+8*num_digits:9*num_digits,2:end) = eight(end:-1:end-num_digits+1,:);
    trainingy(1+9*num_digits:end,2:end) = nine(end:-1:end-num_digits+1,:);
    
    % loop through the training set:
    for i = 1:sqrt(N)
        i
        % for each example in the set, compare it to all other examples:
        for j = 1:sqrt(N)
            
            x = trainingx(i,2:end);
            y = trainingy(j,2:end);
            x_digit = trainingx(i,1);
            y_digit = trainingy(j,1);
            
            if(x_digit == y_digit)
                labels(t_count) = 1;
            else
                labels(t_count) = -1;
            end
            
            % only compare each corresponding pixel - compare pixel 1 to 1,
            % etc.  Throw out the comparisons of pixel 1 to 2,3,...,256
            T(t_count,:) = diag(x'*y)';
            t_count = t_count + 1;
        end
    end
    % in the end, we have a matrix of N^2 rows, each 256 wide
    
    w = T\labels;


end

